//
//  CustomImage.m
//  PigMarket
//
//  Created by 张敬 on 2019/8/14.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "CustomImage.h"


@implementation CustomImage

- (instancetype)init{
    
    self = [super init];
    if (self) {
        [self addSubview:self.cancelLab];
        self.image = [UIImage imageNamed:@"meat_complaint_add"];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addImage)];
        [self addGestureRecognizer:tap];
        self.userInteractionEnabled = YES;
        
    }
    return self;
}


- (void)layoutSubviews{
    
    [super layoutSubviews];
    _cancelLab.size = CGSizeMake(20, 20);
    _cancelLab.mj_x = self.height - 12;
    _cancelLab.mj_y = -8;
    [self addShadowAndCircleCorner:_cancelLab.layer corner:_cancelLab.height/2.0];
}


- (void)cancelImage{
    
    if (self.cancelImageBlock) {
        self.cancelImageBlock();
    }
}

- (void)addImage{
    
    if ([self.image isEqual:[UIImage imageNamed:@"meat_complaint_add"]]) {
        if (self.addImageBlock) {
            self.addImageBlock();
        }
    }
}


- (UILabel *)cancelLab{
    
    if (!_cancelLab) {
        _cancelLab = [[UILabel alloc] init];
        _cancelLab.text = @"—";
        _cancelLab.textColor = KWhiteColor;
        _cancelLab.font = mFont(12);
        _cancelLab.backgroundColor = UIColorFromRGB(0xF25C62);
        _cancelLab.layer.borderWidth = 2;
        _cancelLab.layer.borderColor = KWhiteColor.CGColor;
        _cancelLab.textAlignment = NSTextAlignmentCenter;
        _cancelLab.userInteractionEnabled = YES;
        _cancelLab.hidden = YES;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cancelImage)];
        [_cancelLab addGestureRecognizer:tap];
        
    }
    return _cancelLab;
}

@end
